package com.feicheng.controller.shop.wx.fuwu.client;


import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.alibaba.fastjson.JSONObject;
import com.feicheng.common.constant.Constant;
import com.feicheng.common.result.ResultInfo;
import com.feicheng.controller.BaseController;
import com.feicheng.persistence.entity.Account;
import com.feicheng.persistence.entity.Client;
import com.feicheng.service.IFClientService;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author cailongyang
 * @since 2021-12-02
 */
@RestController("/wx/s/client/deposit-back-request")
@RequestMapping("/wx/s/client/deposit-back-request")
public class DepositBackRequestController extends BaseController {

    @Autowired
    HttpServletRequest request;

    @Autowired
    IFClientService fClientService;

    @GetMapping("/info")
    public ResultInfo getBackInfo(Integer backId) {
        return fClientService.getDepositBackRequest(backId);
    }

    @PostMapping("/info")
    public ResultInfo newBackInfo(String reason) {
        JSONObject param = new JSONObject();

        JSONObject current = getCurrentToken().getToken().getJSONObject(Constant.RESULT.CURRENT);
        Client currentClient = current.getObject(Constant.ENTITY.CLIENT.TABLE, Client.class);
        Account currentAccount = current.getObject(Constant.ENTITY.ACCOUNT.TABLE, Account.class);

        param.put(Constant.ENTITY.DEPOSIT_BACK_REQUEST.CLIENT_ID, currentClient.getClientId());
        param.put(Constant.ENTITY.DEPOSIT_BACK_REQUEST.AMOUNT, currentAccount.getDepositAmount());
        param.put(Constant.ENTITY.DEPOSIT_BACK_REQUEST.REASON, reason);
        param.put(Constant.ENTITY.DEPOSIT_BACK_REQUEST.UU, currentClient.getClientId());

        ResultInfo result = fClientService.newDepositBackRequest(param);


        return result;
    }



}
